package com.itheima.mapper;

import com.itheima.entity.OperateLog;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface OperateLogMapper {

    // 插入日志数据
    @Insert("INSERT INTO operate_log (operate_emp_id, operate_time, class_name, method_name, method_params, return_value, cost_time) " +
            "VALUES (#{operateEmpId}, #{operateTime}, #{className}, #{methodName}, #{methodParams}, #{returnValue}, #{costTime});")
    void insert(OperateLog log);

    @Select("SELECT id, operate_emp_id AS operateEmpId, operate_time AS operateTime, " +
            "class_name AS className, method_name AS methodName, method_params AS methodParams, " +
            "return_value AS returnValue, cost_time AS costTime " +
            "FROM operate_log LIMIT #{offset}, #{pageSize}")
    List<OperateLog> getLogPage(@Param("offset") int offset, @Param("pageSize") int pageSize);

    @Select("SELECT COUNT(*) FROM operate_log")
    long getTotalLogs();

    @Select("SELECT name FROM emp WHERE id = #{operateEmpId}")
    String getEmpNameById(Integer operateEmpId);
}